package com.biscuit.page.basicservice.model.enums;

import lombok.Getter;

import java.util.Arrays;

/**
 * @author biscuit
 * @createTime 2024/5/23 13:50
 */
@Getter
public enum VerifyCodeWorkTypeEnum {

    LOGIN_VERIFY_CODE(1, "verify_code:login:", "登录验证码"),
    REGISTER_VERIFY_CODE(2, "verify_code:register:", "注册验证码"),
    RESET_PASSWORD_VERIFY_CODE(3, "verify_code:reset_password:", "重置密码验证码"),
    CHECK_MOBILE_VERIFY_CODE(4, "verify_code:update_mobile:", "校验手机号验证码"),
    CHECK_EMAIL_VERIFY_CODE(5, "verify_code:update_email:", "校验邮箱验证码");

    // 验证码类型
    private final int type;

    // 验证码缓存前缀
    private final String prefix;

    // 类型描述
    private final String desc;

    VerifyCodeWorkTypeEnum(int type, String prefix, String desc) {
        this.type = type;
        this.prefix = prefix;
        this.desc = desc;
    }

    /**
     * 根据验证码类型获取验证码类型枚举
     *
     * @param type 验证码类型
     * @return 验证码枚举
     */
    public static VerifyCodeWorkTypeEnum getEnumByType(int type) {
        return Arrays.stream(VerifyCodeWorkTypeEnum.values())
                .filter(x -> x.type == type).findFirst().orElse(null);
    }

}
